
#include "ednn.h"
#include "ednn_port.h"



static ednn_ret input_forward(struct ednn_layer *layer)
{
    struct ednn_layer_input *input = (struct ednn_layer_input *)layer;
    
    if ((input->input == EDNN_NULL) || (input->input->pd == EDNN_NULL)) {
        ednn_err("input tensor not set");
        return ednn_err_param;
    }

    if (ednn_tensor_shape_compare(input->input, layer->output) != 0) {
        ednn_err("input:{%d,%d,%d} but need:{%d,%d,%d}", 
            input->input->dim[0], 
            input->input->dim[1],
            input->input->dim[2],
            input->input_shape.h,
            input->input_shape.w, 
            input->input_shape.c
        );
        return ednn_err_param;
    }
    
    ednn_memcpy(layer->output->pd, input->input->pd, ednn_tensor_size(input->input));

    return ednn_ok;
}

static ednn_ret input_build(struct ednn_layer *layer)
{
    return ednn_ok;
}

struct ednn_layer *ednn_input_layer(ednn_shape3d_t shape)
{
    struct ednn_layer_input *layer = ednn_mem_zalloc(sizeof(struct ednn_layer_input));
    ednn_assert(layer != EDNN_NULL);

    layer->super.type    = EDNN_LAYER_INPUT;
    layer->super.forward = input_forward;
    layer->super.build   = input_build;

    layer->input_shape = shape;
    ednn_uint16_t dim[3] = {shape.h, shape.w, shape.c};
    layer->super.output = ednn_tensor_create(dim, 3);

    return (struct ednn_layer *)layer;
}